package com.meichis.yndms.adapter;

import android.content.Context;
import android.content.Intent;

import com.meichis.mcsappframework.adapter.recyclerview.CommonAdapter;
import com.meichis.mcsappframework.adapter.recyclerview.base.ViewHolder;
import com.meichis.yndms.R;
import com.meichis.yndms.common.MCode;
import com.meichis.yndms.model.ClientInfo;
import com.meichis.yndms.ui.activity.ClientDetailActivity;

import java.util.ArrayList;

public class ClientAdapter extends CommonAdapter<ClientInfo> {
    private Context context;

    public ClientAdapter(Context context, int layoutId, ArrayList<ClientInfo> datas) {
        super(context, layoutId, datas);
        this.context = context;
    }

    @Override
    protected void convert(ViewHolder viewHolder, final ClientInfo item, int position) {
        viewHolder.setText(R.id.tv_clientName, item.getFullName());
        viewHolder.setText(R.id.tv_address, item.getAddress());
        viewHolder.setText(R.id.tv_distance, item.getDistance() > 0 ? item.getDistance() + "米" : "");
        viewHolder.setText(R.id.tv_tel, item.getMobile());

        viewHolder.setOnClickListener(R.id.tv_distance, view -> {
            Intent intent = new Intent();

            intent.putExtra(MCode.CLIENT, item);
            // intent.setClass(context, ClientLocationActivity.class);
            //context.startActivity(intent);
        });

        viewHolder.setOnClickListener(R.id.ll, view -> {
            Intent intent = new Intent();

            intent.putExtra(MCode.CLIENT, item);
            intent.setClass(context, ClientDetailActivity.class);
            context.startActivity(intent);
        });

    }
}
